package ltd.smallwang.infrastructure.task.db.convert;

import ltd.smallwang.domain.task.TaskExecuteRecord;
import ltd.smallwang.domain.task.constant.RecordByEnum;
import ltd.smallwang.infrastructure.task.db.model.TaskExecuteRecordPo;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;
import org.mapstruct.factory.Mappers;

/**
 * @author justd
 * @description 功能描述
 * @since 2024-05-12 20:00
 **/
@Mapper
public interface TaskExecuteRecordConvert {

  TaskExecuteRecordConvert INSTANCE = Mappers.getMapper(TaskExecuteRecordConvert.class);

  @Mapping(source = "recordByEnum", target = "recordBy", qualifiedByName = "recordByEnumToInteger")
  TaskExecuteRecordPo convert(TaskExecuteRecord taskExecuteRecord);

  @Named("recordByEnumToInteger")
  default Integer recordByEnumToInteger(RecordByEnum recordByEnum) {
    return recordByEnum.getRecordBy();
  }

  @Mapping(source = "recordBy", target = "recordByEnum", qualifiedByName = "integerToRecordByEnum")
  TaskExecuteRecord convert(TaskExecuteRecordPo taskExecuteRecordPo);

  @Named("integerToRecordByEnum")
  default RecordByEnum recordByEnumToInteger(Integer recordBy) {
    return RecordByEnum.init(recordBy);
  }
}
